home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / user-setup / user-setup-ask < prev   
Text File  |  2008-10-07  |  8KB  |  276 lines

  1. #!/bin/sh -e
  2.  
  3. . /usr/share/debconf/confmodule
  4.  
  5. db_capb "backup"
  6.  
  7. if [ "$1" ]; then
  8.     ROOT="$1"
  9. else
  10.     ROOT=
  11. fi
  12. export ROOT
  13.  
  14. . /usr/lib/user-setup/functions.sh
  15.  
  16. # For the convenience of heavy testers
  17. set_special_users() {
  18.     local realname
  19.     case "$fullname" in
  20.         fjp)    realname="Frans Pop" ;;
  21.         tbm)    realname="Martin Michlmayr" ;;
  22.         *)        return 1 ;;
  23.     esac
  24.     db_set passwd/user-fullname "$realname"
  25.     userdefault=$fullname
  26.     db_fset passwd/username seen true
  27.     return 0
  28. }
  29.  
  30. # Main loop starts here. Use a state machine to allow jumping back to
  31. # previous questions.
  32. STATE=0
  33. while :; do
  34.     case "$STATE" in
  35.         0)
  36.         # Ask how the password files should be set up.
  37.         db_input low passwd/shadow || true
  38.         # Ask if root should be allowed to login.
  39.         db_input medium passwd/root-login || true
  40.         ;;
  41.         1)
  42.         db_get passwd/root-login
  43.         if [ "$RET" = false ]; then
  44.             # root password will be locked
  45.             db_set passwd/root-password ""
  46.             db_set passwd/root-password-crypted "!"
  47.         elif ! root_password; then
  48.             # First check whether the root password was preseeded
  49.             # crypted to an actual password (not locked)
  50.             db_get passwd/root-password-crypted || true
  51.             if ! test "$RET" || [ "x$RET" = "x!" ]; then
  52.                 # No preseed of the root password hash
  53.                 # we will prompt the user
  54.                 db_set passwd/root-password-crypted ""
  55.                 db_input critical passwd/root-password || true
  56.                 db_input critical passwd/root-password-again || true
  57.             fi
  58.         fi
  59.         ;;
  60.         2)
  61.         db_get passwd/root-login
  62.         if [ "$RET" = false ]; then
  63.             # root password will be locked
  64.             db_set passwd/root-password-again ""
  65.         elif ! root_password; then
  66.             # First check whether the root password was preseeded crypted
  67.             db_get passwd/root-password-crypted || true
  68.             if ! test "$RET" ; then
  69.                 # Compare the two passwords, loop back if not
  70.                 # identical, or if empty.
  71.                 db_get passwd/root-password
  72.                 ROOT_PW="$RET"
  73.                 if [ -z "$ROOT_PW" ]; then
  74.                     db_fset user-setup/password-empty seen false
  75.                     db_input critical user-setup/password-empty
  76.                     db_fset passwd/root-password seen false
  77.                     db_fset passwd/root-password-again seen false
  78.                     STATE=0
  79.                     continue
  80.                 fi
  81.                 db_get passwd/root-password-again
  82.                 if [ "$ROOT_PW" != "$RET" ]; then
  83.                     db_fset user-setup/password-mismatch seen false
  84.                     db_input critical user-setup/password-mismatch
  85.                     db_fset passwd/root-password seen false
  86.                     db_fset passwd/root-password-again seen false
  87.                     STATE=0
  88.                     continue
  89.                 fi
  90.                 ROOT_PW=''
  91.             fi
  92.         fi
  93.         ;;
  94.         3)
  95.         # Ask if a non-root user should be made, if there is not
  96.         # already one.
  97.         db_get passwd/root-login
  98.         if [ "$RET" = false ]; then
  99.             # always make non-root user; this user will be able
  100.             # to sudo to root
  101.             db_set passwd/make-user true
  102.         elif ! is_system_user; then
  103.             db_input medium passwd/make-user || true
  104.         fi
  105.         ;;
  106.         4)
  107.         # Prompt for user info.
  108.         db_get passwd/make-user
  109.         if [ "$RET" = true ] && ! is_system_user; then
  110.             db_input critical passwd/user-fullname || true
  111.         fi
  112.         ;;
  113.         5)
  114.         # Prompt for user info.
  115.         db_get passwd/make-user
  116.         if [ "$RET" = true ] && ! is_system_user; then
  117.             LOOP=""
  118.             db_get passwd/username
  119.             if [ -z "$RET" ]; then
  120.                 db_get passwd/user-fullname
  121.                 fullname=$RET
  122.                 if ! set_special_users; then
  123.                     userdefault=$(echo "$fullname" | \
  124.                         sed 's/ .*//' | LC_ALL=C tr A-Z a-z)
  125.                 fi
  126.                 if test -n "$userdefault" && \
  127.                     LC_ALL=C expr "$userdefault" : '[a-z][-a-z0-9]*$' >/dev/null; then
  128.                     db_set passwd/username "$userdefault"
  129.                 fi
  130.             fi
  131.             db_input critical passwd/username || true
  132.         fi
  133.         ;;
  134.         6)
  135.         # Verify user.
  136.         db_get passwd/make-user
  137.         if [ "$RET" = true ] && ! is_system_user; then
  138.             # Verify the user name, loop with message if bad.
  139.             db_get passwd/username
  140.             USER="$RET"
  141.             if ! LC_ALL=C expr "$USER" : '[a-z][-a-z0-9]*$' >/dev/null; then
  142.                 db_fset passwd/username seen false
  143.                 db_fset passwd/username-bad seen false
  144.                 db_input critical passwd/username-bad
  145.                 STATE=3
  146.                 continue
  147.             fi
  148.             
  149.             if grep -v '^#' /usr/lib/user-setup/reserved-usernames | \
  150.                grep -q "^$USER\$"; then
  151.                 db_fset passwd/username seen false
  152.                 db_fset passwd/username-reserved seen false
  153.                 db_subst passwd/username-reserved USERNAME "$USER"
  154.                 db_input critical passwd/username-reserved
  155.                 STATE=3
  156.                 continue
  157.             fi
  158.  
  159.             db_get passwd/user-password-crypted || true
  160.             if ! test "$RET" ; then
  161.                 db_input critical passwd/user-password || true
  162.                 db_input critical passwd/user-password-again || true
  163.             fi
  164.         fi
  165.         ;;
  166.         7)
  167.         db_get passwd/make-user
  168.         if [ "$RET" = true ] && ! is_system_user; then
  169.             db_get passwd/user-password-crypted || true
  170.             if ! test "$RET" ; then
  171.                 # Compare the two passwords, loop with message if not
  172.                 # identical
  173.                 db_get passwd/user-password
  174.                 USER_PW="$RET"
  175.                 db_get passwd/user-password-again
  176.                 if [ "$USER_PW" != "$RET" ]; then
  177.                     db_set passwd/user-password ""
  178.                     db_set passwd/user-password-again ""
  179.                     db_fset user-setup/password-mismatch seen false
  180.                     db_input critical user-setup/password-mismatch
  181.                     db_fset passwd/user-password seen false
  182.                     db_fset passwd/user-password-again seen false
  183.                     STATE=6
  184.                     continue
  185.                 fi
  186.                 # Loop if the password is empty, and it's not
  187.                 # specifically allowed by preseeding
  188.                 db_get passwd/allow-password-empty
  189.                 if [ "$RET" = false ] && [ -z "$USER_PW" ]; then
  190.                     db_set passwd/user-password ""
  191.                     db_set passwd/user-password-again ""
  192.                     db_fset user-setup/password-empty seen false
  193.                     db_input critical user-setup/password-empty
  194.                     db_fset passwd/user-password seen false
  195.                     db_fset passwd/user-password-again seen false
  196.                     STATE=6
  197.                     continue
  198.                 fi
  199.             fi
  200.         fi
  201.         ;;
  202.         8)
  203.         db_get passwd/make-user
  204.         if [ "$RET" = true ]; then
  205.             db_input high user-setup/encrypted-private || true
  206.         fi
  207.         ;;
  208.         9)
  209.         db_get passwd/make-user
  210.         if [ "$RET" = true ]; then
  211.             db_get user-setup/encrypted-private
  212.             if [ "$RET" = true ]; then
  213.                 db_input critical user-setup/encrypted-private-passphrase || true
  214.             fi
  215.         fi
  216.         ;;
  217.         10)
  218.         db_get passwd/make-user
  219.         if [ "$RET" = true ]; then
  220.             db_get user-setup/encrypted-private
  221.             if [ "$RET" = true ]; then
  222.                 db_get user-setup/encrypted-private-passphrase
  223.                 if [ "$RET" ]; then
  224.                     db_input critical user-setup/encrypted-private-passphrase-again || true
  225.                 fi
  226.             fi
  227.         fi
  228.         ;;
  229.         11)
  230.         db_get passwd/make-user
  231.         if [ "$RET" = true ]; then
  232.             db_get user-setup/encrypted-private
  233.             if [ "$RET" = true ]; then
  234.                 db_get user-setup/encrypted-private-passphrase
  235.                 ENCRYPTION_PW="$RET"
  236.                 if [ "$ENCRYPTION_PW" ]; then
  237.                     db_get user-setup/encrypted-private-passphrase-again
  238.                     if [ "$ENCRYPTION_PW" != "$RET" ]; then
  239.                         db_set user-setup/encrypted-private-passphrase ""
  240.                         db_set user-setup/encrypted-private-passphrase-again ""
  241.                         db_fset user-setup/password-mismatch seen false
  242.                         db_input critical user-setup/password-mismatch
  243.                         db_fset user-setup/encrypted-private-passphrase seen false
  244.                         db_fset user-setup/encrypted-private-passphrase seen false
  245.                         STATE=9
  246.                         continue
  247.                     fi
  248.                 else
  249.                     ENCRYPTION_PW="$(head -c 16 /dev/urandom | od -x | head -n 1 | sed 's/^0000000//' | sed 's/\s*//g')"
  250.                     db_set user-setup/encrypted-private-passphrase "$ENCRYPTION_PW"
  251.                     db_subst user-setup/encrypted-private-passphrase-display PASSPHRASE "$ENCRYPTION_PW"
  252.                     db_input critical user-setup/encrypted-private-passphrase-display
  253.                 fi
  254.             fi
  255.         fi
  256.         ;;
  257.         12)
  258.         db_subst user-setup/encrypted-private-passphrase-display PASSPHRASE ''
  259.         ;;
  260.         *)
  261.         break
  262.         ;;
  263.     esac
  264.  
  265.     if db_go; then
  266.         STATE=$(($STATE + 1))
  267.     else
  268.         STATE=$(($STATE - 1))
  269.     fi
  270.     #echo "ON STATE: $STATE"
  271. done
  272.  
  273. if [ "$STATE" = -1 ]; then
  274.     exit 10
  275. fi
  276.